<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div></div>
    <script>
        let div = document.querySelector("div");
        let btn = document.querySelector('button');
        let ajax = new XMLHttpRequest()
        ajax.open('get', '/index');
        ajax.send()
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
                // console.log(JSON.parse(ajax.responseText));
                let data = JSON.parse(ajax.responseText)
                let str = '';
                data.forEach(value => {
                    str += `<ul>
                    <li><img src="${value.picture}" alt=""></li>
                    <li>商品名称:${value.tradeName}</li>
                    <li>价格:${value.price}</li>
                    <li>股票:${value.stock}</li>
                </ul>`
                });
                div.innerHTML = str;
            }
        }
    </script>
</body>

</html>